package oracle.springbootxm.controller;

import oracle.springbootxm.pojo.GoodsInfo;
import oracle.springbootxm.pojo.UserInfo;
import oracle.springbootxm.service.GoodsService;
import oracle.springbootxm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/register")
    public String addUserInfo(UserInfo userInfo) {
        if (!StringUtils.isEmpty(userInfo.getUsername()) && !StringUtils.isEmpty(userInfo.getPassword()) && !StringUtils.isEmpty(userInfo.getPhonenumber())) {
            System.out.println("注册成功");
            userService.addUserInfo(userInfo);
            return "login";
        }
        System.out.println("来了老弟");
        return null;
    }

    @RequestMapping("/jumpregister")
    public String addUserInfo() {
        return "register";
    }

    @RequestMapping("/superregister")
    public String addSuperUser(UserInfo userInfo){
        if (!StringUtils.isEmpty(userInfo.getUsername()) && !StringUtils.isEmpty(userInfo.getPassword()) && !StringUtils.isEmpty(userInfo.getPhonenumber())) {
            System.out.println("注册成功");
            userInfo.setUserpower(1);
            userService.addSuperUserInfo(userInfo);
            return "login";
        }
        return null;
    }

}
